package fr.ups.jim.isi.tp4;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;

public class RectangleItem extends CanvasItem {

	Point startPoint , endPoint;
	
	RectangleItem (PersistentCanvas canvas, Color oColor, Color fColor, Point p) 
	{
		super(canvas, oColor, fColor);
		startPoint = new Point(p.x, p.y);
		shape = new Rectangle(p.x, p.y, 0, 0);
	}

	RectangleItem (RectangleItem originItem) {
		super(originItem.canvas, originItem.outlineColor, originItem.fillColor);
		shape = new Rectangle((Rectangle)originItem.shape);
	}
	
	public void update(Point p) {
		endPoint = new Point(p.x, p.y);
		((Rectangle)shape).setFrameFromDiagonal(startPoint, endPoint);
		canvas.repaint();
	}


	public CanvasItem duplicate() {
		CanvasItem newRectangle = new RectangleItem(this);
		newRectangle.move(10, 10);
		canvas.addItem(newRectangle);
		return newRectangle;
	}
	
	public void move(int disX, int disY) {
		((Rectangle)shape).x += disX;
		((Rectangle)shape).y += disY;
		canvas.repaint();
	}
}
